/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.figures.connection;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PolylineDecoration;
import org.eclipse.swt.graphics.Color;


/**
 * Figure that represents a connection with a solid line.
 */
public class SolidLineFigure extends EdgeFigure {

	/**
	 * Creates a new SolidLineFigure with a default arrow.
	 */
	public SolidLineFigure() {
		super();
		setStyle();
	}
	
	/**
	 * Creates a new SolidLineFigure with given parameters.
	 * 
	 * @param lineWidth the width of the link
	 * @param foregroundColor the foreground color of the link
	 * @param backgroundColor the background color of the link
	 */
	public SolidLineFigure(int lineWidth) {
		super();
		setStyle(lineWidth);
	}
	
	/**
	 * Creates a new SolidLineFigure with given parameters.
	 * 
	 * @param lineWidth the width of the link
	 * @param foregroundColor the foreground color of the link
	 * @param backgroundColor the background color of the link
	 */
	public SolidLineFigure(Color backgroundColor, Color foregroundColor, int lineWidth) {
		super();
		setStyle(backgroundColor, foregroundColor, lineWidth);
	}
	
	/**
	 * Sets initial Style for the figure.
	 * It does not give any special Color for Background and Foreground. This
	 * is the style used for classic arrows: ------>
	 */
	protected void setStyle() {
		PolylineDecoration dec=new PolylineDecoration();
		dec.setScale( 15, 5);
		dec.setLineWidth(1);
		this.setTargetDecoration(dec); // arrow at target endpoint
	}
	
	/**
	 * Sets initial style for this figure.
	 * This is the style used for full arrows: ------|>
	 * 
	 * @param lineWidth the width of the link
	 * @param foregroundColor the foreground color of the link
	 * @param backgroundColor the background color of the link
	 */
	protected void setStyle(int lineWidth) {
		setStyle();
		// set link appearence
		setLineWidth(lineWidth);
	}

	/**
	 * Sets initial style for this figure.
	 * This is the style used for full arrows: ------|>
	 * 
	 * @param lineWidth the width of the link
	 * @param foregroundColor the foreground color of the link
	 * @param backgroundColor the background color of the link
	 */
	protected void setStyle(Color backgroundColor, Color foregroundColor, int lineWidth) {
		// set the target arrow style
		PolygonDecoration dec = new PolygonDecoration();
		dec.setScale( 15, 5);
		dec.setBackgroundColor( backgroundColor);
		dec.setLineWidth(1);
		setTargetDecoration(dec);
		
		// set link appearence
		setLineStyle(Graphics.LINE_SOLID);  // line drawing style
		setLineWidth(lineWidth);
		setForegroundColor( foregroundColor);
	}
	
	/**
	 * 
	 * 
	 * @param graphics 
	 */
	@Override
	public void paintFigure(Graphics graphics) {
		graphics.pushState();
		super.paintFigure(graphics);
		if (img!=null){
		super.FillFigure(graphics);}
		graphics.popState();
	}
	
	/*DOC*/
	/*protected void outlineShape(Graphics g) {
		PointList pointList = getPoints();
		Point source = pointList.getFirstPoint();
		Point target = pointList.getLastPoint();
		
                // It isn't the good calcul, it's just to test
		int x = target.x;
		int y = target.y;
		int width = (int) source.getDistance(target);
		g.drawArc(target.x, target.y, width, width, 90, 180);
	}*/
	
	}